<?

require_once("layout_config.php");
require_once("include/project.php");
require_once("include/permission.php");
require_once("include/html_utils.php");

$user_id = permission_redirect_user("login.php");
$project = $_REQUEST['project'];
$sprint  = $_REQUEST['sprint'];

if ($_SERVER['REQUEST_METHOD'] == "POST") {
	$pbacklog   = $_REQUEST['pbacklog'];
	$estimation = $_REQUEST['estimation'];
	$unit       = $_REQUEST['unit'];
	$status	    = $_REQUEST['status'];

	$story_id = sprint_create_backlog($pbacklog, $status, $unit, $estimation, $sprint);
	if ($story_id > 0) {
		header("location: sprints.php?project=$project&sprint=$sprint");
	}
}

?>
<html>
<head>
<title><?=$layout_project_name?></title>
<link type="text/css" rel="stylesheet" href="themes/<?=$layout_theme; ?>/main.css" />
</head>
<body>
<table width="450" border="0" cellpadding="0" cellspacing="0" align="center">
<form method="post" action="story_add.php" id="story_add">
<input type="hidden" name="project" id="project" value="<?=$project ?>" />
<input type="hidden" name="sprint" id="sprint" value="<?=$sprint ?>" />
	<tr>
		<td rowspan="3" class="form_left" width="40">&nbsp;</td>
		<td height="20" class="form_title">&nbsp;New Story</td>
	</tr>
	<tr>
		<td>
		<br>
		<table width="95%" border="0" cellpadding="1" cellspacing="1" align="center">
		<tr>
			<td align="right" height="20"><?=_("Project Backlog");?>:&nbsp;</td>
			<td width="176" colspan="2">
				<select id="pbacklog" name="pbacklog">
					<? echo html_select_pbacklog($project); ?>
				</select>
			</td>
		</tr>
		<tr>
			<td align="right" height="20"><?=_("Estimation");?>:&nbsp;</td>
			<td width="176">
				<input type="text" id="estimation" name="estimation" class="form_input" />
			</td>
			<td width="80">
				<select id="unit" name="unit" class="sprint_units">
				<? echo html_select_unitlist(); ?>
				</select>
			</td>
		</tr>
		<tr>
			<td align="right" height="20"><?=_("Status");?>:&nbsp;</td>
			<td>
				<select id="status" name="status">
				<? echo html_select_statuslist(); ?>
				</select>
			</td>
		</tr>
		<tr>
			<td colspan="3" class="form_separator">&nbsp;</td>
		</tr>
		</table>
		<table width="99%" border="0" cellpadding="1" cellspacing="1">
			<tr>
				<td align="right" height="40">
					<a href="javascript: story_add.submit()">
					<img src="themes/<?=$layout_theme; ?>/images/btn_save.jpg" border="0" />
					</a>
				</td>
				<td width="65">
					<a href="sprints.php?project=<?=$project?>&sprint=<?=$sprint?>">
					<img src="themes/<?=$layout_theme; ?>/images/btn_cancel.jpg" border="0" />
					</a>
				</td>
			</tr>
		</table>
		</td>
	</tr>
	<tr>
		<td class="form_left" height="4"> </td>
	</tr>
</form>
</table>
</body>
</html>
